﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit.Electric.Common;
using HYCodeBase.WinForm;

namespace ElectricDim
{
	public partial class DlgCableTrayTypeDim : DlgModelLess
	{
		public DlgCableTrayTypeDim(UIApplication uiApp, WindowHandle handel) : base(handel)
		{
			this.mApp = uiApp;
			this.InitializeComponent();
		}

		public static DlgCableTrayTypeDim GetInstance(UIApplication app, WindowHandle handel)
		{
			if (DlgCableTrayTypeDim.dll == null || DlgCableTrayTypeDim.dll.IsDisposed)
			{
				DlgCableTrayTypeDim.dll = new DlgCableTrayTypeDim(app, handel);
			}
			return DlgCableTrayTypeDim.dll;
		}

		public LeaderStyle GetDimStyle()
		{
			if (this.rbNullLeader.Checked)
			{
				return LeaderStyle.None;
			}
			if (this.rbHasLeader.Checked)
			{
				return LeaderStyle.HasLeader;
			}
			return LeaderStyle.Orthogonal;
		}

		public PointStyle GetDimLinkStyle()
		{
			if (this.rbNull.Checked)
			{
				return PointStyle.None;
			}
			if (this.rbArrow.Checked)
			{
				return PointStyle.Arrow;
			}
			return PointStyle.Circle;
		}

		public string GetMarkTypeName()
		{
			return this.selectedItemObject.Name;
		}

		public Autodesk.Revit.DB.ElementType GetElementType()
		{
			Autodesk.Revit.DB.ElementType result = null;
			if (this.selectedItemObject != null)
			{
				Family labelFamily = this.selectedItemObject.LoadInSubTrans(this.mApp.ActiveUIDocument.Document);
				result = ElectricalUtils.GetLeaderType(this.mApp.ActiveUIDocument.Document, this.GetDimLinkStyle(), labelFamily);
			}
			return result;
		}

		private void DlgCableTrayTypeDim_Load(object sender, EventArgs e)
		{
			this.beLoad = true;
			foreach (DbFamilyObject item in ElectricMark.CableTrayMark(this.mApp.ActiveUIDocument.Document))
			{
				this.cbxFamily.Items.Add(item);
			}
			if (this.cbxFamily.Items.Count > 0)
			{
				this.cbxFamily.SelectedIndex = 0;
			}
			this.beLoad = false;
		}

		private void cbxFamily_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.cbxFamily.SelectedItem != null)
			{
				this.selectedItemObject = (this.cbxFamily.SelectedItem as DbFamilyObject);
				this.pbxFamily.Image = this.selectedItemObject.GetImage();
			}
			if (this.beLoad)
			{
				return;
			}
			Cursor.Position = new System.Drawing.Point(base.Right + 1, base.Bottom + 1);
			base.turnToRevit();
			base.SendESC();
			this.ManaulEsc = true;
		}

		private void rbNullLeader_CheckedChanged(object sender, EventArgs e)
		{
			this.groupBox3.Enabled = !this.rbNullLeader.Checked;
		}

		private UIApplication mApp;

		private bool beLoad;

		public bool ManaulEsc;

		private DbFamilyObject selectedItemObject;

		private static DlgCableTrayTypeDim dll;
	}
}
